<template>
	<view class="container">
<view  @click="changimage"   style="width: 100rpx;height: 100rpx; background-color: #00FFFF;border-radius: 100rpx; display: flex;flex-direction: row;align-items: center; justify-content: center;" >
	<image :src="'http://localhost:8090'+user.icon" style="width: 80rpx;" mode="widthFix" ></image>
</view>
<uni-list v-show="!flag">
	<uni-list-item title="修改密码" note=""></uni-list-item>
	<uni-list-item title="电话" note="" :rightText="user.telephone"></uni-list-item>
</uni-list>
<button type="default" @click="login" v-show="flag">登录</button>
<button type="default" @click="outLogin" v-show="!flag">退出登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			flag:true,
				user:{}
			}
		},
		methods: {
			login(){
				uni.navigateTo({
					url:"login/login"
				})
			},
			
			outLogin(){
				uni.clearStorageSync(),
				this.user={},
				this.flag=true
			},
			
			
			
			
changimage(){
	if(!this.flag){
	uni.chooseImage({
		count:1,
		success: (res) => {
			console.log(res);
			if(res.tempFilePaths.length>0){
				let FilePath=res.tempFilePaths[0]
				let File=res.tempFiles[0]
				uni.uploadFile({
						url: 'http://localhost:8090/foodapp/uploadheadicon',
						filePath: FilePath,
						name: 'headicon',
						formData: {
							'file': File,
							"id":this.user.id
						},
						success: (sres) => {
							console.log(sres.data);
						let	res=JSON.parse(sres.data)
						console.log(res);
						if(res.success){
						this.user.icon=res.headiconpath
						}
						}
					});
			}
		}
	})
	}
}


		},
	onShow() {
		this.user=uni.getStorageSync('user')
		if(this.user!=""&&this.user!=null){
			this.flag=false
		}
		console.log(this.user);
	}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
